package com.finance.cooperate.feature.builder.submodel.support.intermediate;

import com.finance.cooperate.common.constant.Constant;
import com.finance.cooperate.common.utils.StringUtil;
import com.finance.cooperate.dao.local.cache.SmsCategoryCache;
import com.finance.cooperate.feature.base.ReaderImpl;
import com.finance.cooperate.feature.core.feature.FeatureDefinition;

import java.util.Map;

/**
 * @ClassName IntermediateFeature002
 * @Description app 分层与逾期短信组合
 * @Author shenanxin
 * @Date 2023/9/21 14:55
 * @Modify ...
 */
public class IntermediateFeature002 extends ReaderImpl {

    @Override
    public Map<String, String> read(String userId) {


        String appLevelV1Str = super.get(FeatureDefinition.f_app_competition_level_v1);

        if (!StringUtil.isEmptyOrNvl(appLevelV1Str)) {

            Integer appLevel = Integer.parseInt(appLevelV1Str);

            SmsCategoryCache.getTimeSplitsV1().forEach((k, v) -> {

                String overdueCountStr = super.get(FeatureDefinition.f_sms_loan_v1_.getValue() + "overdue_" + k);

                if (!StringUtil.isEmptyOrNvl(overdueCountStr)) {

                    Integer overdueCount = Integer.parseInt(overdueCountStr);

                    if (overdueCount > 0) {

                        super.put(FeatureDefinition.f_intermediate_competition_.getValue() + "v1_overdue_" + k, appLevel);

                    }

                }

            });


        }



        String appLevelV2Str = super.get(FeatureDefinition.f_app_competition_level_v2);

        if (!StringUtil.isEmptyOrNvl(appLevelV2Str)) {

            Integer appLevel = Integer.parseInt(appLevelV2Str);

            SmsCategoryCache.getTimeSplitsV1().forEach((k, v) -> {

                String overdueCountStr = super.get(FeatureDefinition.f_sms_loan_v1_.getValue() + "overdue_" + k);

                if (!StringUtil.isEmptyOrNvl(overdueCountStr)) {

                    Integer overdueCount = Integer.parseInt(overdueCountStr);

                    if (overdueCount > 0) {

                        super.put(FeatureDefinition.f_intermediate_competition_.getValue() + "v2_overdue_" + k, appLevel);

                    }

                }

            });


        }




        return super.getResult();
    }
}
